package ch.fhnw.kosmonauten.client.gui;

import java.awt.Graphics;
import java.util.Arrays;

import javax.swing.border.EmptyBorder;

import ch.fhnw.kosmonauten.client.core.HexagramModification;
import ch.fhnw.kosmonauten.model.User;
import ch.fhnw.kosmonauten.client.core.Utility;

/**
 * Diese Klasse stellt das Hexagram-Panel dar.
 * 
 * @author Fabian Siegrist
 * @author Oliver Freiermuth
 * @author Mikhail Onoufrienko
 * @author Risto Milani
 * @version $Revision: 160 $
 *          File name: $HeadURL: http://iching-kosmonauten.googlecode.com/svn/I-Ching/src/ch/fhnw/kosmonauten/client/gui/HGPanel.java $
 *          Last modified:$Date: 2013-05-26 11:05:04 +0000 (Sun, 26 May 2013) $
 *          Last modified by: $Author: molotok.mihon@gmail.com $
 */

// class definition
public class HGPanel extends javax.swing.JPanel {

	// attributes
	private User user;
	private ch.fhnw.kosmonauten.client.gui.Hexagram guihex;
	private ch.fhnw.kosmonauten.model.Hexagram modelhex;
	private LineText lt1;
	private LineText lt2;
	private LineText lt3;
	private LineText lt4;
	private LineText lt5;
	private LineText lt6;
	private LineNote ln1;
	private LineNote ln2;
	private LineNote ln3;
	private LineNote ln4;
	private LineNote ln5;
	private LineNote ln6;
	private HGText ht;
	private HGComment hc;
	public boolean paint;

	// constructors
	/**
	 * Creates new form NuclearPanel
	 * 
	 * @param paint
	 * @param hex
	 */
	public HGPanel(boolean paint, ch.fhnw.kosmonauten.model.Hexagram hex, User user) {
		this.user = user;
		this.modelhex = hex;
		this.guihex =  new Hexagram(Utility.convertStringToArray(modelhex.getBinarycode()),37,60);
		this.paint = paint;
		this.add(guihex);
		initComponents();
	}

	/**
	 * @param paint
	 */
	public HGPanel(boolean paint, User user) {
		//guihex = new Hexagram(new int[]{6,7,8,9,6,6},37,60);
		//this.add(guihex);
		this.user = user;
		this.paint = paint;
		initComponents();
	}
	
	public LineNote getLn1() {
		return ln1;
	}

	public void setLn1(LineNote ln1) {
		this.ln1 = ln1;
	}

	public LineNote getLn2() {
		return ln2;
	}

	public void setLn2(LineNote ln2) {
		this.ln2 = ln2;
	}

	public LineNote getLn3() {
		return ln3;
	}

	public void setLn3(LineNote ln3) {
		this.ln3 = ln3;
	}

	public LineNote getLn4() {
		return ln4;
	}

	public void setLn4(LineNote ln4) {
		this.ln4 = ln4;
	}

	public LineNote getLn5() {
		return ln5;
	}

	public void setLn5(LineNote ln5) {
		this.ln5 = ln5;
	}

	public LineNote getLn6() {
		return ln6;
	}

	public void setLn6(LineNote ln6) {
		this.ln6 = ln6;
	}
	
	public ch.fhnw.kosmonauten.model.Hexagram getModelhex() {
		return modelhex;
	}

	public void setModelhex(ch.fhnw.kosmonauten.model.Hexagram modelhex) {
		this.modelhex = modelhex;
	}

	public ch.fhnw.kosmonauten.client.gui.Hexagram getGuihex() {
		return guihex;
	}

	public void setGuihex(ch.fhnw.kosmonauten.model.Hexagram modelhex) {
		this.guihex = new Hexagram(HexagramModification.getHexagramCode(Utility.convertStringToArray(modelhex.getBinarycode())),37,60);
		this.jButton5.setText(modelhex.getHexagramname());
		this.add(guihex);
	}
	
	// methods
	/*
	 * (non-Javadoc)
	 * 
	 * @see javax.swing.JComponent#paintComponent(java.awt.Graphics)
	 */
	@Override
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		if (this.paint)
		{
			guihex.paintComponent(g);
		}
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	@SuppressWarnings("unchecked")
	// <editor-fold defaultstate="collapsed" desc="Generated Code">
	private void initComponents() {

		jButton15 = new javax.swing.JButton();
		jButton5 = new javax.swing.JButton();
		jButton6 = new javax.swing.JButton();
		jButton12 = new javax.swing.JButton();
		jButton13 = new javax.swing.JButton();
		jButton8 = new javax.swing.JButton();
		jButton7 = new javax.swing.JButton();
		jButton14 = new javax.swing.JButton();
		jButton9 = new javax.swing.JButton();
		jButton10 = new javax.swing.JButton();
		jButton16 = new javax.swing.JButton();
		jButton17 = new javax.swing.JButton();
		jButton11 = new javax.swing.JButton();
		jScrollPane1 = new javax.swing.JScrollPane();
		jTextArea1 = new javax.swing.JTextArea();
		jLabel1 = new javax.swing.JLabel();
		jScrollPane2 = new javax.swing.JScrollPane();
		jTextArea2 = new javax.swing.JTextArea();
		jLabel2 = new javax.swing.JLabel();
		jButton30 = new javax.swing.JButton();
		jButton31 = new javax.swing.JButton();

		jButton15.setText(user.displayValue("mw84"));
		jButton15.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton15ActionPerformed(evt);
			}
		});

		jButton5.setText(user.displayValue("mw85"));
		jButton5.setBorder(new EmptyBorder(5,5,5,5));
		jButton5.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton5ActionPerformed(evt);
			}
		});

		jButton6.setText(user.displayValue("mw86"));
		jButton6.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton6ActionPerformed(evt);
			}
		});

		jButton12.setText(user.displayValue("mw87"));
		jButton12.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton12ActionPerformed(evt);
			}
		});

		jButton13.setText(user.displayValue("mw88"));
		jButton13.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton13ActionPerformed(evt);
			}
		});

		jButton8.setText(user.displayValue("mw89"));
		jButton8.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton8ActionPerformed(evt);
			}
		});

		jButton7.setText(user.displayValue("mw90"));
		jButton7.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton7ActionPerformed(evt);
			}
		});

		jButton14.setText(user.displayValue("mw91"));
		jButton14.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton14ActionPerformed(evt);
			}
		});

		jButton9.setText(user.displayValue("mw92"));
		jButton9.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton9ActionPerformed(evt);
			}
		});

		jButton10.setText(user.displayValue("mw93"));
		jButton10.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton10ActionPerformed(evt);
			}
		});

		jButton16.setText(user.displayValue("mw94"));
		jButton16.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton16ActionPerformed(evt);
			}
		});

		jButton17.setText(user.displayValue("mw95"));
		jButton17.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton17ActionPerformed(evt);
			}
		});

		jButton11.setText(user.displayValue("mw96"));
		jButton11.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton11ActionPerformed(evt);
			}
		});

		jTextArea1.setColumns(20);
		jTextArea1.setRows(5);
		jScrollPane1.setViewportView(jTextArea1);

		jLabel1.setText(user.displayValue("mw97"));

		jTextArea2.setColumns(20);
		jTextArea2.setRows(5);
		jScrollPane2.setViewportView(jTextArea2);

		jLabel2.setText(user.displayValue("mw98"));

		jButton30.setText(user.displayValue("mw99"));
		jButton30.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton30ActionPerformed(evt);
			}
		});

		jButton31.setText(user.displayValue("mw100"));
		jButton31.addActionListener(new java.awt.event.ActionListener() {
			@Override
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				jButton31ActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.LEADING)
												.addGroup(
														layout.createSequentialGroup()
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addGap(61,
																										61,
																										61)
																								.addComponent(
																										jButton5,
																										javax.swing.GroupLayout.PREFERRED_SIZE,
																										232,
																										javax.swing.GroupLayout.PREFERRED_SIZE))
																				.addGroup(
																						layout.createSequentialGroup()
																								.addGap(269,
																										269,
																										269)
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.LEADING)
																												.addGroup(
																														layout.createSequentialGroup()
																																.addGroup(
																																		layout.createParallelGroup(
																																				javax.swing.GroupLayout.Alignment.LEADING)
																																				.addComponent(
																																						jButton7,
																																						javax.swing.GroupLayout.Alignment.TRAILING)
																																				.addComponent(
																																						jButton9,
																																						javax.swing.GroupLayout.Alignment.TRAILING))
																																.addPreferredGap(
																																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																																.addGroup(
																																		layout.createParallelGroup(
																																				javax.swing.GroupLayout.Alignment.LEADING)
																																				.addComponent(
																																						jButton14)
																																				.addComponent(
																																						jButton15)))
																												.addGroup(
																														layout.createSequentialGroup()
																																.addComponent(
																																		jButton8)
																																.addPreferredGap(
																																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																																.addComponent(
																																		jButton13))
																												.addGroup(
																														layout.createParallelGroup(
																																javax.swing.GroupLayout.Alignment.LEADING,
																																false)
																																.addGroup(
																																		layout.createSequentialGroup()
																																				.addGroup(
																																						layout.createParallelGroup(
																																								javax.swing.GroupLayout.Alignment.LEADING)
																																								.addComponent(
																																										jButton10,
																																										javax.swing.GroupLayout.Alignment.TRAILING)
																																								.addComponent(
																																										jButton11,
																																										javax.swing.GroupLayout.Alignment.TRAILING))
																																				.addPreferredGap(
																																						javax.swing.LayoutStyle.ComponentPlacement.RELATED,
																																						javax.swing.GroupLayout.DEFAULT_SIZE,
																																						Short.MAX_VALUE)
																																				.addGroup(
																																						layout.createParallelGroup(
																																								javax.swing.GroupLayout.Alignment.LEADING)
																																								.addComponent(
																																										jButton16)
																																								.addComponent(
																																										jButton17)))
																																.addGroup(
																																		layout.createSequentialGroup()
																																				.addComponent(
																																						jButton6)
																																				.addPreferredGap(
																																						javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																																				.addComponent(
																																						jButton12))))))
																.addGap(0,
																		0,
																		Short.MAX_VALUE))
												.addGroup(
														layout.createSequentialGroup()
																.addContainerGap()
																.addGroup(
																		layout.createParallelGroup(
																				javax.swing.GroupLayout.Alignment.LEADING)
																				.addComponent(
																						jScrollPane1,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						825,
																						Short.MAX_VALUE)
																				.addComponent(
																						jScrollPane2,
																						javax.swing.GroupLayout.DEFAULT_SIZE,
																						825,
																						Short.MAX_VALUE)
																				.addGroup(
																						layout.createSequentialGroup()
																								.addGroup(
																										layout.createParallelGroup(
																												javax.swing.GroupLayout.Alignment.LEADING)
																												.addGroup(
																														layout.createSequentialGroup()
																																.addComponent(
																																		jLabel1)
																																.addPreferredGap(
																																		javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																																.addComponent(
																																		jButton30))
																												.addComponent(
																														jLabel2))
																								.addPreferredGap(
																										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
																								.addComponent(
																										jButton31)
																								.addGap(0,
																										0,
																										Short.MAX_VALUE)))))
								.addContainerGap()));
		layout.setVerticalGroup(layout
				.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
				.addGroup(
						layout.createSequentialGroup()
								.addComponent(jButton5)
								.addGap(10, 10, 10)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jButton6)
												.addComponent(jButton12))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jButton8)
												.addComponent(jButton13))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jButton7)
												.addComponent(jButton14))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jButton9)
												.addComponent(jButton15))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jButton10)
												.addComponent(jButton16))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jButton11)
												.addComponent(jButton17))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel1)
												.addComponent(jButton30))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(jScrollPane1,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										56, Short.MAX_VALUE)
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addGroup(
										layout.createParallelGroup(
												javax.swing.GroupLayout.Alignment.BASELINE)
												.addComponent(jLabel2)
												.addComponent(jButton31))
								.addPreferredGap(
										javax.swing.LayoutStyle.ComponentPlacement.RELATED)
								.addComponent(jScrollPane2,
										javax.swing.GroupLayout.DEFAULT_SIZE,
										56, Short.MAX_VALUE).addContainerGap()));
	}// </editor-fold>

	/**
	 * @param evt
	 */
	private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {
		if (ln3 == null)
			ln3 = new LineNote(this.modelhex.getHexagramname(), "3", user);
		else
			ln3.setVisible(true);
	}

	/**
	 * @param evt
	 */
	private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {
		if (lt6 == null)
			lt6 = new LineText(modelhex.getHexagramname(), "6",modelhex.getLine6text());
		else
			lt6.setVisible(true);
	}

	/**
	 * @param evt
	 */
	private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {
		if (ln6 == null)
			ln6 = new LineNote(this.modelhex.getHexagramname(), "6", user);
		else
			ln6.setVisible(true);
	}

	/**
	 * @param evt
	 */
	private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {
		if (ln5 == null)
			ln5 = new LineNote(this.modelhex.getHexagramname(), "5", user);
		else
			ln5.setVisible(true);
	}

	/**
	 * @param evt
	 */
	private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {
		if (lt5 == null)
			lt5 = new LineText(modelhex.getHexagramname(), "5",modelhex.getLine5text());
		else
			lt5.setVisible(true);
	}

	/**
	 * @param evt
	 */
	private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
		if (lt4 == null)
			lt4 = new LineText(modelhex.getHexagramname(), "4",modelhex.getLine4text());
		else
			lt4.setVisible(true);
	}

	/**
	 * @param evt
	 */
	private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {
		if (ln4 == null)
			ln4 = new LineNote(this.modelhex.getHexagramname(), "4", user);
		else
			ln4.setVisible(true);
	}

	/**
	 * @param evt
	 */
	private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
		if (lt3 == null)
			lt3 = new LineText(modelhex.getHexagramname(), "3",modelhex.getLine3text());
		else
			lt3.setVisible(true);
	}

	/**
	 * @param evt
	 */
	private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {
		if (lt2 == null)
			lt2 = new LineText(modelhex.getHexagramname(), "2",modelhex.getLine2text());
		else
			lt2.setVisible(true);
	}

	/**
	 * @param evt
	 */
	private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {
		if (ln2 == null)
			ln2 = new LineNote(this.modelhex.getHexagramname(), "2", user);
		else
			ln2.setVisible(true);
	}

	/**
	 * @param evt
	 */
	private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {
		if (ln1 == null)
			ln1 = new LineNote(this.modelhex.getHexagramname(), "1", user);
		else
			ln1.setVisible(true);
	}

	/**
	 * @param evt
	 */
	private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {
		if (lt1 == null)
			lt1 = new LineText(modelhex.getHexagramname(), "1",modelhex.getLine1text());
		else
			lt1.setVisible(true);
	}

	/**
	 * @param evt
	 */
	private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		ht = new HGText(modelhex.getHexagramname(), modelhex.getJudge(),modelhex.getComment(), user);
	}

	/**
	 * @param evt
	 */
	private void jButton30ActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		hc = new HGComment(12, "ein Name", false, user);
	}

	/**
	 * @param evt
	 */
	private void jButton31ActionPerformed(java.awt.event.ActionEvent evt) {
		// TODO add your handling code here:
		hc = new HGComment(12, "ein Name", true, user);
	}

	// Variables declaration - do not modify
	private javax.swing.JButton jButton10;
	private javax.swing.JButton jButton11;
	private javax.swing.JButton jButton12;
	private javax.swing.JButton jButton13;
	private javax.swing.JButton jButton14;
	private javax.swing.JButton jButton15;
	private javax.swing.JButton jButton16;
	private javax.swing.JButton jButton17;
	private javax.swing.JButton jButton30;
	private javax.swing.JButton jButton31;
	private javax.swing.JButton jButton5;
	private javax.swing.JButton jButton6;
	private javax.swing.JButton jButton7;
	private javax.swing.JButton jButton8;
	private javax.swing.JButton jButton9;
	private javax.swing.JLabel jLabel1;
	private javax.swing.JLabel jLabel2;
	private javax.swing.JScrollPane jScrollPane1;
	private javax.swing.JScrollPane jScrollPane2;
	private javax.swing.JTextArea jTextArea1;
	private javax.swing.JTextArea jTextArea2;
	// End of variables declaration
	
	
	
	public javax.swing.JTextArea getjTextArea1() {
		return jTextArea1;
	}

	public void setjTextArea1(javax.swing.JTextArea jTextArea1) {
		this.jTextArea1 = jTextArea1;
	}

	public javax.swing.JTextArea getjTextArea2() {
		return jTextArea2;
	}

	public void setjTextArea2(javax.swing.JTextArea jTextArea2) {
		this.jTextArea2 = jTextArea2;
	}

	
}
